const Home =()=>import (/*webpackChunkName:'home'*/'pages/home/Home')
const Login =()=>import (/*webpackChunkName:'login'*/'pages/login/Login')
const Register =()=>import (/*webpackChunkName:'register'*/'pages/register/Register')
const Search =()=>import (/*webpackChunkName:'search'*/'pages/search/Search')
const ShopCart =()=>import (/*webpackChunkName:'shopCart'*/'pages/shopCart/ShopCart')
const Detail =()=>import (/*webpackChunkName:'detail'*/'pages/detail/Detail')
const AddCartSuccess =()=>import (/*webpackChunkName:'addCartSuccess'*/'pages/addCartSuccess')
const A =()=>import (/*webpackChunkName:'a'*/'pages/guard/A')
const B =()=>import (/*webpackChunkName:'b'*/'pages/guard/B')
const C =()=>import (/*webpackChunkName:'b'*/'pages/guard/C')
const Trade =()=>import (/*webpackChunkName:'trade'*/'pages/trade')
const Pay =()=>import (/*webpackChunkName:'pay'*/'pages/pay')
const PaySuccess =()=>import (/*webpackChunkName:'paySuccess'*/'pages/paySuccess')
const Center =()=>import (/*webpackChunkName:'center'*/'pages/center')
const MyOrder =()=>import (/*webpackChunkName:'center'*/'pages/center/myOrder/MyOrder')
const GroupOrder =()=>import (/*webpackChunkName:'center'*/'pages/center/groupOrder/GroupOrder')
import store from 'store'
export default[
    {path:'/home',component:Home},
    {path:'/login',component:Login,meta:{hiddenFooter:true},
    beforeEnter: (to, from, next) => {
        const userInfo = store.state.user.userInfo
        if(userInfo.name){
            //如果是登录状态
            next('/')
        }else{
            next()
        }
    }
        
    },
    {path:'/register',component:Register,meta:{hiddenFooter:true}},
    {name:'search', path:'/search/:keyword?',component:Search,
        props:({params:{keyword=''},query:{categoryName='',category1Id='',category2Id='',category3Id=''}})=>({
            keyword,
            categoryName,
            category1Id,
            category2Id,
            category3Id
        })
    },
    {path:'/detail/:id',component:Detail,props:true},
    {path:'/shopCart',component:ShopCart},
    {path:'/addCartSuccess',component:AddCartSuccess,props:({query:{skuNum}})=>({skuNum})},
    {path:'/trade',component:Trade,beforeEnter(to, from,next){
        if(from.path.split('/')[1] === 'shopcart'){
            next()
        }else{
            next('/shopcart')
        }
    }},
    {path:'/pay',component:Pay,meta:{hiddenFooter:true},beforeEnter(to, from,next){
        if(from.path.split('/')[1] === 'trade'){
            next()
        }else{
            next('/shopcart')
        }}
    },
    {path:'/paySuccess',component:PaySuccess,beforeEnter(to, from,next){
        if(from.path.split('/')[1] === 'pay'){
            next()
        }else{
            next('/shopcart')
        }},},
    {path:'/center',component:Center,
        children:[
        {path:'myorder',component:MyOrder},
        {path:'grouporder',component:GroupOrder},
        {path:'/center',redirect:'/center/myorder'},
    ]},
    {name:'A',path:'/a',component:A},
    {name:'B',path:'/b',component:B,
        beforeEnter: (to, from, next) => {
            console.log('b路由组件的路由独享守卫beforeEnter')
            next()
    }},
    {name:'C',path:'/c/:id',component:C,
        beforeEnter: (to, from, next) => {
        console.log('c路由组件的路由独享守卫beforeEnter')
        next()
    }},
    {path:'/',redirect:'/home'}
]